import 'dart:ui';

/// Screen Util.
/// @author slc
class ScreenUtil {
  double _screenWidth = 0.0;
  double _screenHeight = 0.0;
  double _screenDensity = 0.0;
  double _statusBarHeight = 0.0;
  double _bottomBarHeight = 0.0;

  static final ScreenUtil _singleton = ScreenUtil();

  static ScreenUtil getInstance() {
    _singleton._init();
    return _singleton;
  }

  _init() {
    FlutterView flutterView = PlatformDispatcher.instance.views.first;
    Size size = flutterView.physicalSize;
    ViewPadding padding = flutterView.viewPadding;
    _screenWidth = size.width;
    _screenHeight = size.height;
    _screenDensity = flutterView.devicePixelRatio;
    _statusBarHeight = padding.top;
    _bottomBarHeight = padding.bottom;
  }

  /// screen density
  /// 屏幕 像素密度
  double get screenDensity => _screenDensity;

  /// screen width
  /// 屏幕 宽
  double get screenWidth => _screenWidth;
  double get screenWidthDpr => _screenWidth / _screenDensity;

  /// screen height
  /// 屏幕 高
  double get screenHeight => _screenHeight;
  double get screenHeightDpr => _screenHeight / _screenDensity;

  /// status bar Height
  /// 状态栏高度
  double get statusBarHeight => _statusBarHeight;
  double get statusBarHeightDpr => _statusBarHeight / _screenDensity;

  /// bottom bar Height
  double get bottomBarHeight => _bottomBarHeight;
  double get bottomBarHeightDpr => _bottomBarHeight / _screenDensity;

}
